#include "Game.h"
#include "Timer.h"
#include "SDL.h"

const int FRAMES_PER_SECOND = 60;

int main( int argc, char* args[] )
{
    Game game = Game();
	Timer delta = Timer();
	Timer fps = Timer();
	Timer update = Timer();
	int frame = 0;
	bool quit = false;
    
	//Initialize all SDL and screen components.
	if (game.initComponents() == false) {
		return 1;
	}

	//load game content
	if (game.loadContent() == false) {
		return 2;
	}

	//Main game loop
	delta.start();
	update.start();
	fps.start();
	while (quit == false) {
		
		//handle game input
		if (game.handleInput() == false) {
			quit = true;
		}

		//update game
		game.update(delta.getTicks());

		//reset the delta timer
		delta.start();

		//draw game
		game.draw();

		if (update.getTicks() > 1000) {
			std::stringstream caption;
			caption << "Average Frames Per Second: " << frame / (fps.getTicks() / 1000.0f);
			SDL_WM_SetCaption(caption.str().c_str(), NULL);
			update.start();
		}
		frame++;
	}

	//unload game content
	game.unloadContent();

	//uninitialize SDL components
	game.uninitComponents();
    
    return 0;    
}